//
//  XMLHomeToolBarView.swift
//  Weibo
//
//  Created by mac on 16/5/13.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

//ToolBar视图

class XMLHomeToolBarView: UIView {
    
    var homeCellViewModel :XMLHomeCellViewModel? {
    
        didSet {
        
            retweetButton.setTitle(homeCellViewModel?.retweetCountContent, forState: .Normal)
            commentButton.setTitle(homeCellViewModel?.commentCountContent, forState: .Normal)
            unlikeButton.setTitle(homeCellViewModel?.unlikeCountContent, forState: .Normal)
            
        }
    }
    
    private lazy var retweetButton :UIButton = self.addSubButtons("转发", imageName :"timeline_icon_retweet")
    private lazy var commentButton :UIButton = self.addSubButtons("评论", imageName :"timeline_icon_comment")
    private lazy var unlikeButton :UIButton = self.addSubButtons("赞", imageName :"timeline_icon_unlike")
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        addSubviews()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func addSubviews() {
    
//        backgroundColor = UIColor.orangeColor()
        let firstLine = addLine()
        let secondLine = addLine()
        
        retweetButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(commentButton)
        }
        commentButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(retweetButton.snp_trailing)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(unlikeButton)
        }
        unlikeButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(commentButton.snp_trailing)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(retweetButton)
            make.trailing.equalTo(self)
        }
        firstLine.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetButton.snp_trailing)
            make.centerY.equalTo(self)
        }
        secondLine.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentButton.snp_trailing)
            make.centerY.equalTo(self)
        }
    }
    
    private func addSubButtons(title :String, imageName :String)->UIButton {
    
        let button = UIButton()
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        button.setImage(UIImage(named: imageName), forState: .Normal)
        button.adjustsImageWhenHighlighted = false
        button.setTitle(title, forState: .Normal)
        button.setTitleColor(UIColor.grayColor(), forState: .Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        addSubview(button)
        
        return button
    }
    private func addLine()->UIView {
    
        let view = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(view)
        
        return view
        
    }

}
